<template>
  <div class="app-container">
    <div>
      <el-form>
        <el-row class="rowFormItem">

          <el-col :span="3" style="margin-right: 10px;">
            <el-input v-model="keyword" placeholder="请输入类型名称进行搜索" />
          </el-col>
          <el-col :span="3">
            <el-select v-model="status" placeholder="禁用或启用">
              <el-option v-for="opt in options" :key="opt.id" :value="opt.id" :label="opt.label" />
            </el-select>
          </el-col>

          <el-col :span="5" class="clear">
            <el-form-item style="text-align: left;width: 300px;margin-left: 5px;">
              <el-button type="primary" size="large" @click="handleSubmit()">检索</el-button>
              <el-button type="warning" size="large" style="margin-left: 8px;" @click="handleReset()">重置</el-button>
              <el-button type="success" @click="add" size="large">新建</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>


    <div class="tableClass" style="margin-top: 15px">
      <el-table :data="formdata" v-loading="loading" :header-cell-style="{background:'#eef1f6',color:'#606266'}" border
                style="width: 100%;">
        <el-table-column align="center" prop="id" label="序号" />
        <el-table-column align="center" prop="name" label="拼团活动名称"/>
        <el-table-column align="center" prop="require_num" label="成团人数" />
        <el-table-column align="center" prop="time_limit" label="成团时效/小时" />
        <el-table-column align="center" prop="" label="活动对象">
          <template slot-scope="scope">
           <div>全部用户</div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="status" label="状态">
          <template slot-scope="scope">
            <div v-if="scope.row.status==0"><el-tag size="small" type="danger">禁用</el-tag></div>
            <div v-if="scope.row.status==1"><el-tag size="small">启用</el-tag></div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="start_time" label="开始时间" />
        <el-table-column align="center" prop="end_time" label="结束时间" />
        <el-table-column label="操作" align="center" width="230px">
          <template slot-scope="scope">
           <router-link :to="{path:'/marketingManage/groupActivities/addGroupActivities',query:{id:scope.row.id}}">
              <el-button size="mini" type="primary">编辑</el-button>
           </router-link>
            <el-button class="btnAppeal" size="mini" style="margin-left: 5px;" type="danger" @click="delMsg(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <br>
      <!-- 分页 -->
      <div style="text-align: center;">
        <el-pagination background layout="prev, pager, next" @current-change="pageChange" :page-size="pageSize" :total="totalusers" />
      </div>
    </div>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        keyword:"",
        status:"",
        form: {
          id: "",
          name: "",
          desc: "",
          sort: "",
          status: "0",
        },
        options: [{
          id: '0',
          label: "禁用"
        }, {
          id: '1',
          label: "启用"
        }],
        loading: false,
        formdata: [],
        totalusers: 0, //总行数
        pageSize: 5, //每页几行
        startpage: 1, //起始页
      }
    },
    mounted() {
      this.getSystemGroupList()
    },
    methods: {

      add(){
        window.localStorage.setItem("groupItem",'')
        this.$router.push({path: '/marketingManage/groupActivities/addGroupActivities'})
      },

      handleSubmit(){
        this.getSystemGroupList()
      },
      handleReset(){
        this.keyword=""
        this.status=""
      },
      //获取分页列表
      getSystemGroupList() {
        this.formdata = []
        let params = {
          "page": this.startpage,
          "limit": this.pageSize,
          "keyword":this.keyword,
          "status":this.status
        }
        //调用后台提供的接口方法
        this.$api.getSystemGroupList(params).then(res => {
          console.log(res)
          if (res.data.level == "success") {
            this.formdata = res.data.data
            this.totalusers = res.data.page_info.total
            this.loading = false
          } else {
            this.$message.error(res.data.message)
            this.loading = false
          }
        })
      },
      //分页 pageChange当前页发生改变触发函数
      async pageChange(page) {
        this.startpage = page
        this.loading = true
        // window.sessionStorage.setItem("pageOne",this.startpage)
        //调用获取列表的方法
        this.getSystemGroupList()
      },

      //删除信息
      async delMsg(id) {
        let delid = {
          id: id
        }
        await this.$confirm('删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          const loadingOne = this.$loading({
            lock: true,
            text: '保存中...',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          })
          this.$api.delSystemGroup(delid).then(res => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            if (res.data.level == "success") {
              loadingOne.close()
              this.getSystemGroupList()
            } else {
              this.$message.error(res.data.message)
              loadingOne.close()
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },


    }
  }
</script>
<style scoped="scoped">
  /deep/.el-card__header {
    background-color: #409EFF;
    color: whitesmoke;
  }

  /deep/.el-dialog {
    margin-top: 10vh !important;
    width: 33%;
  }

  .msgDiv {
    width: 80%;
    margin: auto;
    text-align: center;
  }

  .el-input {
    display: flex;
    flex-grow: <2>;
  }
</style>
